<template>
	<view :style="$store.state.skin">
		<view class="password">
			<view class="password_box">
				<view class="pw_col border">
					<view class="col-1">原密码</view>
					<view class="col-2">
						<input class="uni-input pw-input" v-model="password" password placeholder="原密码" />
					</view>
				</view>
				<view class="pw_col border">
					<view class="col-1">新密码</view>
					<view class="col-2">
						<input class="uni-input pw-input" v-model="newPassword" password placeholder="新密码" />
					</view>
				</view>
				<view class="pw_col border">
					<view class="col-1 m">重复密码</view>
					<view class="col-2">
						<input class="uni-input pw-input" v-model="repeatPassword" password placeholder="重复密码" />
					</view>
				</view>
			</view>
			<view class="button_box" @click="sub">
				<view class="button">确定</view>
			</view>
		</view>
	</view>
</template>

<script>
import request from '@/api/request.js';
export default {
	data() {
		return {
			password: '',
			newPassword: '',
			repeatPassword: '',
			PayPwd: 0 // 0 修改登录密码 1 修改交易密码
		};
	},
	onLoad(option) {
		this.PayPwd = Number(option.PayPwd);
		if (option.PayPwd == 0) {
			uni.setNavigationBarTitle({
				title: '修改登录密码'
			});
		} else {
			uni.setNavigationBarTitle({
				title: '修改交易密码'
			});
		}
	},
	onShow() {
		// 设置导航栏颜色
		uni.setNavigationBarColor({
			frontColor: '#ffffff',
			backgroundColor: this.$store.state.presentColor
		});
	},
	methods: {
		// 确定
		async sub() {
			if (this.password === '' || this.newPassword === '' || this.repeatPassword === '') {
				uni.showToast({
					title: '请填写完整',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			if (this.newPassword != this.repeatPassword) {
				uni.showToast({
					title: '重复密码不一致',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			let url = '';
			let json = {};
			if (this.PayPwd === 1) {
				url = '/api/user/resetPayPwd';
				json = {
					new_pay_password: this.newPassword,
					old_pay_password: this.password
				};
			} else {
				url = '/api/user/resetPwd';
				json = {
					new_password: this.newPassword,
					old_password: this.password
				};
			}
			// 还没写完
			let data = await request.post(url, json);
			if (data.code === 1) {
				uni.showToast({
					title: data.msg,
					duration: 2000,
					icon: 'none'
				});
				uni.switchTab({
					url: '/pages/mine/mine'
				});
			}
		}
	}
};
</script>

<style scoped lang="scss">
.password {
	padding: 0rpx 40rpx;
	.password_box {
		background-color: #ffffff;
		border-bottom-right-radius: 16rpx;
		border-bottom-left-radius: 16rpx;
		height: 400rpx;
		.pw_col {
			height: 110rpx;
			display: flex;
			align-items: center;
			.col-1 {
				color: #212121;
				margin-left: 20rpx;
				margin-right: 60rpx;
			}
			.m {
				margin-right: 26rpx;
			}
			.col-2 {
				padding-right: 10rpx;
				flex: 1;
				.pw-input {
					width: 100%;
				}
			}
		}
	}
	.button_box {
		height: 100rpx;
		width: 100%;
		margin-top: 30rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 10rpx;
		background-color: var(--nav-bg);
		color: #ffffff;
	}
}
</style>
